package com.weixiaodong.ModelDesign.适应设计模式.Iterator模式.练习;

import com.weixiaodong.ModelDesign.适应设计模式.Iterator模式.遍历书籍程序案例演示.Book;
import com.weixiaodong.ModelDesign.适应设计模式.Iterator模式.遍历书籍程序案例演示.Iterator;

@SuppressWarnings("all")
public class BookShelfIterator implements Iterator {

    private BookShelf bookShelf;

    private int index;

    public BookShelfIterator(BookShelf bookShelf) {
        this.index = 0;
        this.bookShelf = bookShelf;
    }

    @Override
    public boolean hasNext() {
        return this.index < this.bookShelf.getSize();
    }

    @Override
    public Book next() {
        Book book = this.bookShelf.getBook(index);
        this.index++;
        return book;
    }
}
